const mongo=require("mongodb")
const MongoClient=mongo.MongoClient
const dburl="mongodb://localhost:27017"

function getTestDB(db,callback){
MongoClient.connect(dburl,function(err,client){
   const odb=client.db("db")
   callback(odb)
})
}

function getTestDBSync(db){
    return new Promise(function(resolve,reject){
        MongoClient.connect(dburl,function(err,client){
            if(err){
                reject(err)
            }
            const odb=client.db(db)
            resolve(odb)
         }) 
    })
}

function find(odb,table){
    return new Promise(function(resolve,reject){
         odb.collection(table).find().toArray(function(err,result){
            if(err){
                reject(err)
                return
            }
            resolve(result)
         })
    })
}

module.exports={
    getTestDB,
    getTestDBSync,
    find
}